﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BPM.Entity
{
	/// <summary>
	/// 用户
	/// </summary>
	public class User : BarcodeEntity
	{
		/// <summary>
		/// 登录名
		/// </summary>
		public string UserName { get; set; }
		/// <summary>
		/// 登录密码
		/// </summary>
		public string Password { get; set; }
		/// <summary>
		/// 真实姓名
		/// </summary>
		public string RealName { get; set; }
		/// <summary>
		/// 拥有的Roles
		/// </summary>
		public virtual IList<Role> RoleList { get; set; }
		/// <summary>
		/// 是否通过经理的验证
		/// </summary>
		public bool IsValid { get; set; }

		private ILazyEntityRef<Barcode> _Barcode;
		/// <summary>
		/// 条码
		/// </summary>
		public Barcode Barcode
		{
			get
			{
				return this._Barcode.Entity;
			}
			set
			{
				this._Barcode.Entity = value;
			}
		}
		public int BarcodeId
		{
			get
			{
				return this._Barcode.Id;
			}
			set
			{
				this._Barcode.Id = value;
			}
		}

		public User()
		{
			this._Barcode = this.CreateReference<Barcode>();
		}

		public bool HasRole(int roleId)
		{
			return this.RoleList.Any(r => r.Id == roleId);
		}

		public bool HasRole(Role role)
		{
			return this.HasRole(role.Id);
		}
	}
}